<?php

namespace common\behavior;

use common\service\CommonService;

/**
 * 版本创建后更新任务的最新版本字段
 */
class VersionCreateTaskLatestVersionUpdateBehavior
{
    public function run($params)
    {
        $data = $params['record']['data'];
        if (empty($data['module_id'])
            || $data['module_id'] != module_by_code('task')['id']
            || empty($data['link_id'])
            || $data['link_id'] <= 0
        ) {
            return;
        }
        CommonService::instance('task')->update(['id' => $data['link_id'], 'task_latest_version_id' => $data['id']], 'task', false);
    }
}